package com.paic.mhis.hcpms.assessment.biz.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.paic.mhis.common.base.intergration.dao.CommonDAO;
import com.paic.mhis.hcpms.assessment.biz.service.AssessmentIndicatorService;
import com.paic.mhis.hcpms.assessment.biz.service.ScoreTableService;
import com.paic.mhis.hcpms.assessment.common.AssessmentConstants;
import com.paic.mhis.hcpms.assessment.dto.IndicatorConfigInfoDTO;
import com.paic.mhis.hcpms.assessment.dto.ScoreTableDTO;

/**
 * 
 * Description: 生成医院得分详情表格
 * 
 * @author: EX-ZENGYUANCHAO001
 * @version:
 */
@Service("scoreTableService")
public class ScoreTableServiceImpl implements ScoreTableService {
	@Autowired
	private CommonDAO commonDAO;

	@Autowired
	private AssessmentIndicatorService assessmentIndicatorService;

	@Override
	public List<ScoreTableDTO> createReportsTable(Map<String, Object> map) {
		List<ScoreTableDTO> list = commonDAO.query("scoreTable.findList", map);
		for (int i = 0; i < list.size(); i++) {
			if (StringUtils.equals(list.get(i).getIndicatorLevel() + "",
					AssessmentConstants.INDICATOR_LEVEL3)) {
				IndicatorConfigInfoDTO infoDto = assessmentIndicatorService
						.getIndicatorConfig(list.get(i).getIndicatorCode(),
								(String) map.get("regioncode"),
								(String) map.get("grade"));
				list.get(i).setCompareRange(infoDto.getMethodScope());
				list.get(i).setTimeRange(infoDto.getTimeRange());
				list.get(i).setSourceType(infoDto.getEvaluationMethod());

				if (StringUtils.equals(infoDto.getEvaluationMethod(),
						AssessmentConstants.SOURCE_TYPE2)
						&& (list.get(i).getUpperLimit() == null || list.get(i)
								.getUpperLimit().compareTo(new BigDecimal(0)) == 0)) {
					list.get(i).setLowerLimit(infoDto.getValue());
					list.get(i).setUpperLimit(new BigDecimal(100));
				}
			}
		}
		return list;
	}
}
